#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct pii{
    int fi,se;
    bool operator <(const pii &_)const{
        if(fi != _.fi)return fi < _.fi;
        return se < _.se;
    }
};
inline int fr(int &x){
    char ch = getchar();x = 0;int f = 1;
    for(;!isdigit(ch);ch = getchar())if(ch == '-')f = -1;
    for(;isdigit(ch);ch = getchar())x = (x << 1) + (x << 3) + (ch ^ 48);
    return x *= f;
}
int T,n,m,L,V,head[1000010],pos[1000010],d[100010],v[100010],a[100010],edgecnt,ccnt;
ll dis[1000010];
struct Edge{
    int v,nex,c;
}edge[7500010];
inline void addedge(int u,int v,int c){
    edge[++edgecnt] = {v,head[u],c};
    head[u] = edgecnt;
}
queue<int>qu;
void SPFA(){
    qu.push(0);
    int psh,v;
    while(!qu.empty()){
        psh = qu.front();qu.pop();
        for(int i = head[psh];~i;i = edge[i].nex){
            v = edge[i].v;
            if(dis[v] > dis[psh] + edge[i].c){
                dis[v] = dis[psh] + edge[i].c;qu.push(v);
            }
        }
    }
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    fr(T);
    while(T--){

    memset(head,-1,sizeof(head));memset(edge,0,sizeof(edge));ccnt = 0;memset(pos,0,sizeof(pos));
    double t,xs;
    fr(n);fr(m);fr(L);fr(V);L++;
    for(int i = 1;i <= n;i++){
        fr(d[i]);fr(v[i]);fr(a[i]);d[i]++;
    }
    for(int i = 1;i <= m;i++)pos[fr(ccnt)]++;
    for(int i = 1;i <= L;i++){
        addedge(i - 1,i,pos[i]);
        addedge(i,i - 1,0);
    }
    ccnt = 0;
    for(int i = 1;i <= L;i++)pos[i] += pos[i - 1];
    for(int i = 1;i <= n;i++){
        if(!a[i])if(v[i] > V)if(pos[L] - pos[d[i] - 1] >= 1)addedge(L,d[i] - 1,-1),ccnt++;
        else if(a[i] > 0){
            t = (V - v[i]) * 1.0 / a[i];xs = v[i] * t + a[i] * t * t / 2.0 + d[i];
            if(t < 0.0)if(pos[L] - pos[d[i] - 1] >= 1)addedge(L,d[i] - 1,-1),ccnt++;
            else if(xs < 1.0 * L)if(pos[L] - pos[(int)floor(xs)] >= 1)addedge(L,floor(xs),-1),ccnt++;
        }
        else{
            t = (V - v[i]) * 1.0 / a[i];xs = v[i] * t + a[i] * t * t / 2.0 + d[i];
            if(t > 0.0)if(pos[min(L,(int)ceil(xs) - 1)] - pos[d[i] - 1] >= 1)addedge(min(L,(int)ceil(xs) - 1),d[i] - 1,-1),ccnt++;
        }//cout << ccnt << '\n';
    }
    cout << ccnt << '\n';
    memset(dis,0x3f,sizeof(dis));
    dis[0] = 0;
    SPFA();
    cout << dis[L];

    }
    return 0;
}
